#include <iostream>
#include <cstdio>
typedef long long ll;
using namespace std;
int main() {
    int n;
    cin>>n;
    ll a[n];
    int cnt=0;
    for (int i=0; i<n; i++) {
        scanf("%lld", &a[i]);
        if (a[i]<0) cnt++;
    }
    ll max=0;
    ll tmp=0;
    if (cnt==n) cout<<0<<endl;
    else {
        for (int i=0; i<n; i++) {
            if (tmp<0) tmp=0;
            tmp+=a[i];
            if (tmp>max) max=tmp;
        }
    }
    cout<<max<<endl;
    return 0;
}
